<template>
	<view class="temple">
		<Navbar>庙市</Navbar>
		<view class="content">
			<view class="tab">
				<view class="item" :class="active==1?'active':''" @click="changeActive(1)">藏品</view>
				<view class="item" :class="active==2?'active':''" @click="changeActive(2)">盲盒</view>
			</view>
			<scroll-view scroll-y class="scroll_view" @scrolltolower="loadmore">
				<view class="list">
					<view class="item" v-for="item in list" @click="routerFilter(item.id)" v-if="item.product">
						<image :src="`${baseImageUrl}/home/type1.png`" v-if="active==1" class="type_one"></image>
						<image :src="`${baseImageUrl}/home/type2.png`" v-else class="type_two"></image>
						<image :src="item.product.cover" class="cover"></image>
						<view class="name">{{item.product.name}}</view>
						<view class="price">
							<text class="key">¥</text>
							<text class="value">{{item.product.price}}</text>
						</view>
						<view class="btn">
							<view>查看</view>
						</view>
					</view>
				</view>
				<u-loadmore :status="loadmore_status" :color="$store.state.loadmoreColor"
					:lineColor="$store.state.loadmoreColor" line @loadmore="loadmore" />
			</scroll-view>
		</view>
	</view>
</template>

<script>
	import {
		purchaseLists
	} from '@/request/api.js';
	export default {
		data() {
			return {
				active: 1,
				list: []
			}
		},
		onLoad() {
			this.getList();
		},
		methods: {
			async getList() {
				let {
					list
				} = await purchaseLists({
					page: this.page,
					limit: this.limit,
					product_type: this.active
				});
				this.last_page = list.last_page;
				list = list.list;
				this.list = this.page == 1 ? list : [...this.list, ...list];
				this.loadmore_status = this.last_page == this.page ? 'nomore' : 'loadmore';
			},
			loadmore() {
				if (this.page < this.last_page) {
					this.page++;
					this.getList();
				}
			},
			changeActive(index) {
				this.active = index;
				this.list = [];
				this.page = 1;
				this.getList();
			},
			routerFilter(id) {
				let url = this.active == 1 ? '/pages/home/collection_deta' : '/pages/home/blindbox_deta';
				url = `${url}?id=${id}`;
				this.router(url);
			}
		}
	}
</script>

<style scoped lang="scss">
	.temple {
		height: 100vh;
		background: #29170D;

		.content {
			height: calc(100vh - #{$navbarHeight});
			padding: 0 110rpx 50rpx;
			box-sizing: border-box;
			background: url(#{$baseImageUrl}/bg/bg1.png) no-repeat;
			background-size: 100% 100%;

			.tab {
				height: 124rpx;
				padding: 12rpx 0;
				box-sizing: border-box;
				display: flex;
				justify-content: space-between;

				.item {
					width: 260rpx;
					height: 100rpx;
					line-height: 100rpx;
					text-align: center;
					color: #494338;
					font-size: 48rpx;
					font-weight: 400;
					font-family: LiSu;
					background: url(#{$baseImageUrl}/common/tab.png) no-repeat;
					background-size: 100% 100%;

					&.active {
						background: url(#{$baseImageUrl}/common/tab_active.png) no-repeat;
						background-size: 100% 100%;
					}
				}
			}

			.scroll_view {
				height: calc(100% - 124rpx);

				.list {
					.item {
						width: 100%;
						height: 782rpx;
						margin-bottom: 20rpx;
						padding: 25rpx 20rpx;
						box-sizing: border-box;
						background: url(#{$baseImageUrl}/bg/528_782.png) no-repeat;
						background-size: 100% 100%;
						display: flex;
						flex-direction: column;
						justify-content: space-between;
						position: relative;

						.type_one {
							width: 96rpx;
							height: 150rpx;
							position: absolute;
							left: 12rpx;
							top: 0;
							z-index: 2;
						}

						.type_two {
							width: 102rpx;
							height: 130rpx;
							position: absolute;
							left: 12rpx;
							top: 0;
							z-index: 2;
						}

						.cover {
							width: 100%;
							height: 490rpx;
							border-radius: 20rpx;
						}

						.name {
							color: #494338;
							font-size: 50rpx;
							font-weight: 400;
							font-family: LiSu;
						}

						.label {
							width: 152rpx;
							height: 32rpx;
							line-height: 32rpx;
							text-align: center;
							color: #494338;
							font-size: 24rpx;
							font-weight: 400;
							font-family: SimSun;
							background: url(#{$baseImageUrl}/common/label.png) no-repeat;
							background-size: 100% 100%;
						}

						.price {
							display: flex;
							// align-items: flex-end;
							align-items: center;

							.key {
								color: #494338;
								font-size: 28rpx;
								font-weight: 400;
								font-family: SimSun;
							}

							.value {
								color: #494338;
								font-size: 36rpx;
								font-weight: 400;
								font-family: SimSun;
							}
						}

						.btn {
							display: flex;
							justify-content: flex-end;

							view {
								width: 204rpx;
								height: 74rpx;
								line-height: 74rpx;
								text-align: center;
								color: #FFFFFF;
								font-size: 30rpx;
								font-weight: 400;
								font-family: SimSun;
								background: url(#{$baseImageUrl}/common/btn.png) no-repeat;
								background-size: 100% 100%;
							}
						}
					}
				}
			}
		}
	}
</style>